package cn.waka.sys.admin.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;

@Component
@RefreshScope
@ConfigurationProperties(prefix = "spring.redis")
public class RedisConfig extends JedisPoolConfig {
	private String host;
	private int port;

	private String password;
	
	private int database;
	
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void setDatabase(int database){
		this.database=database;
	}
	/*@Value("${redis.pool.maxTotal}")
	private int maxTotal;
	@Value("${redis.pool.maxIdle}")
	private int maxIdle;
	@Value("${redis.pool.minIdle}")
	private int minIdle;
	@Value("${redis.pool.maxWaitMillis}")
	private int maxWaitMillis=100;
	*/
    @Bean
    @RefreshScope
    public JedisPool redisPool()throws JedisConnectionException {
    	return new JedisPool(this,host,port, 1000, password, database);
    }
}
